#include "SkillsLoader.h"
#include "BaseSkill.h"
#include "SkillHammer.h"
#include "SkillTornado.h"
#include "SkillRain.h"
#include "SkillLightning.h"
#include "SkillMeteor.h"
#include "SkillEarthquake.h"
#include "Supporting/Enums/EnumSkillType.h"

using namespace cocos2d;

//===== CONSTRUCTOR =====
SkillsLoader::SkillsLoader()
{

}

SkillsLoader::~SkillsLoader()
{
}

CCArray* SkillsLoader::getSkillsList()
{
	//load the levels and store into levelList
	CCString skillsFile = CCFileUtils::sharedFileUtils()->fullPathForFilename("Game/Skill/Skills.plist");

	CCArray *skillData = CCArray::createWithContentsOfFileThreadSafe(skillsFile.getCString());
	CCDictionary *skillDataDict = (CCDictionary*)skillData->objectAtIndex(0);

	CCArray* skillListToRead = (CCArray*) skillDataDict->objectForKey("skillArray");
	CCArray *skillsList = new CCArray();

	CCLog("Number of Skills: %d", skillListToRead->count());

	for( int i = 0 ; i < skillListToRead->count() ; i++ )
	{
		CCDictionary *individualskillData = (CCDictionary*)skillListToRead->objectAtIndex(i);

		int skillType = individualskillData->valueForKey("skillType")->intValue();
		CCString* skillName = CCString::createWithFormat("%s",(individualskillData->valueForKey("skillName")->getCString()));
		CCString* skillDescription = CCString::createWithFormat("%s",(individualskillData->valueForKey("skillDescription")->getCString()));

		BaseSkill* newskill = new BaseSkill(skillType,skillName,skillDescription);
		skillsList->addObject(newskill);
	}

	return skillsList;
}

BaseSkill* SkillsLoader::createSkill(int skillType)
{
	BaseSkill* skill;
	switch (skillType)
	{
	case SKILL_RAIN:
		skill = SkillRain::loadSkill("Game/Skill/[Skill] Rain Small.png");
		break;

	case SKILL_EARTHQUAKE:
		skill = SkillEarthquake::loadSkill("Game/Skill/[Skill] Earthquake Small.png");
		break;

	case SKILL_THOR:
		skill = SkillHammer::loadSkill("Game/Skill/[Skill] Thor Hammer Small.png");
		break;

	case SKILL_TORNADO:
		skill = SkillTornado::loadSkill("Game/Skill/[Skill] Tornado Small.png");
		break;

	case SKILL_METEOR:
		skill = SkillMeteor::loadSkill("Game/Skill/[Skill] Meteor Small.png");
		break;

	case SKILL_LIGHTNING:
		skill = SkillLightning::loadSkill("Game/Skill/[Skill] Lightning Small.png");
		break;

	default: //should not happen
		return NULL;
		break;
	}
	return skill;
}

CCArray* SkillsLoader::getSkill(int skillnumber1,int skillnumber2, int skillnumber3)
{
	CCArray* skills = new CCArray();

	for( int i = 0 ; i < 3 ; i++ )
	{
		BaseSkill* skill;
		if( i == 0 )
			skill = createSkill(skillnumber1);
		else if( i == 1 )
			skill = createSkill(skillnumber2);
		else
			skill = createSkill(skillnumber3);

		if( skill != NULL )
			skills->addObject(skill);
	}

	return skills;
}
